﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SharpDiary.Core.Common;
using SharpDiary.Core.Attributes;
using SharpDiary.Core.ORMapping;

namespace SharpDiary.Task
{
    [GuiModule("2ec3064d-e03b-43f8-bf94-b139e49c6380", "ReminderManager", "Ray Shaw(demogodyou@gmail.com)")]
    public partial class frmReminderManager : GuiModuleUIBase
    {
        #region Fields & Properties



        #endregion

        #region Constructors

        public frmReminderManager()
        {
            InitializeComponent();

            reminderInfoListControl.ControlRemoved += new ControlEventHandler(reminderInfoListControl_ControlRemoved);
        }

        private void reminderInfoListControl_ControlRemoved(object sender, ControlEventArgs e)
        {
            UpdateUI();
        }

        #endregion

        #region Methods

        private void UpdateUI()
        {
            toolStripStatusLabel.Text = string.Format("共 {0} 个提醒", ReminderInfo.GetTotalCount());
        }

        public override string GetSettingsKeyName()
        {
            return this.Name;
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            reminderInfoListControl.ShowItems();
            UpdateUI();
        }

        public override void OnMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(sender, e);

            if (e.TargetModuleId.Equals("2ec3064d-e03b-43f8-bf94-b139e49c6380", StringComparison.CurrentCultureIgnoreCase))
            {
                switch (e.MessageInfo)
                {
                    case MessageDefinition.Refresh:
                        {
                            RefreshData();
                            break;
                        }
                }
            }
        }

        #endregion

        /// <summary>
        /// 刷新。
        /// </summary>
        private void RefreshData()
        {
            reminderInfoListControl.ShowItems();
            UpdateUI();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            RefreshData();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            OwnerShell.ExecuteAction("SharpDiary.Reminder", "d53dfd48-fb6f-408f-91d8-009f79e84c09", null, this);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
